﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Threading;

namespace EtlComm
{
    public static class EtlGlobal
    {
        public static string XmlStationFile =  Path.Combine(ApplicationPath, "StationTaskRunInfo.xml");
        public static string XmlTaskFile = Path.Combine(ApplicationPath, "TaskInfo.xml");
        public static string XmlColumnsFile = Path.Combine(ApplicationPath, "ColumnsReference.xml");
        public static string MuilCastAddress = "234.5.6.{0}";
        public static string Public_Key = "BgIAAAAiAABEU1MxAAQAALXh6+TmaNtYku5hqpaOnWnfdZGOZhgTb/sV52M2/6XuDXXA6HbmR18Ghhr9Iv0P9TaUjXS/wG/MOxGV3ZaLwnLJ8gLg4/rwJNtl+k1Ftt4ejj307JvV44ekdYOp7+biL7B372uVwm6+d4zV7rzmJZyWUzjCOD3BPfDRcBptk5GrjzZM22g2WLacPQj2AW7MhR4L+v5vFuoHqQt7JGM/+GZ/4Jt69X3Y16HzdyU3iqxsMZEaw+wHqdJiycvXb3Mecuy1/X3BWVxBzWsauXKepFc3pnv6wi8i9tvM2Yz++SILQtLR20DpC8SdmF/jb1FrvbI425wssHp0bEGR9ZMtoLsH4hF7AJVmOhbq1bIKjkMlcNrJHoOi5ztJy5mKuQi/s3rvR+r5Wp4PXJnbHHExmqIlzixvmWbNiAvGOxtGPjx1rCi+ggnf4XYThSum6yVw9pdio1M2qi4N1dCekNRi6W71ZmO+QUpD3o8W/PkfciYJ9L/DGFPi+FE4/ubLsNFjVaDNt7rIqr0lohGjl3/1Lb7iUy51SwAAAI8bVbjFvPdcglWMTXJlQpnkLfpg";

        //保存XML信号量
        public static Semaphore sk = new Semaphore(240,250);
        //etl启动时间
        public static DateTime EtlStartTime;
        //是否终止
        public static bool IsTerminated;
        //是否进行日志广播
        public static bool IsBrocast;
        //监视线程运行时间
        public static int BeginChek;
        //更新计划延迟多少小时更新
        public static int DelayUpdate;
        //一个任务最大执行时间
        public static int MaxExecuteTimeOut;
        //加油站标记ID
        public static string SID;
        //整表更新的频率
        public static int DelAddRate;
        //普通更新的频率（每调度UpdateRate次进行一次更新）
        public static int UpdateRate;
        //XML文件多少次IO记数进行一次保存操作
        public static int XmlIoSaveCount;

        public static string DT_MAXID = "DT_MAXID";
        //hash表锁
        public static Hashtable LockHt;
        //用于调试用于运行指定的任务 value任务ID，All表示全部
        public static string AllowTask;
        //用于调试用于运行指定的加油站任务 value加油站ID，All表示全部
        public static string AllowStation;
        //每次操作的最大记录数
        public static int MaxRecord;
        //xml更新由哪边保存
        public static string XmlSave;
        //应用程序路径
        public static string ApplicationPath
        {
            get
            {
                return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            }
        }
        /// <summary>
        /// 初始化全局变量
        /// </summary>
        public static void Initialize()
        {
            EtlGlobal.IsTerminated = false;
            EtlGlobal.IsBrocast = bool.Parse(ConfigurationManager.AppSettings["BROCAST"].ToString());
            EtlGlobal.BeginChek = int.Parse(ConfigurationManager.AppSettings["BeginCheck"].ToString());
            EtlGlobal.DelayUpdate = int.Parse(ConfigurationManager.AppSettings["DelayUpdate"].ToString());
            EtlGlobal.MaxExecuteTimeOut = int.Parse(ConfigurationManager.AppSettings["MaxExecuteTime"].ToString());
            EtlGlobal.SID = ConfigurationManager.AppSettings["SID"].ToString();
            EtlGlobal.DelAddRate = int.Parse(ConfigurationManager.AppSettings["DelAddRate"].ToString());
            EtlGlobal.UpdateRate = int.Parse(ConfigurationManager.AppSettings["UpdateRate"].ToString());
            EtlGlobal.XmlIoSaveCount = int.Parse(ConfigurationManager.AppSettings["XmlIoSaveCount"].ToString());
            EtlGlobal.AllowTask = ConfigurationManager.AppSettings["AllowTask"].ToString();
            EtlGlobal.AllowStation = ConfigurationManager.AppSettings["AllowStation"].ToString();
            EtlGlobal.MaxRecord = int.Parse(ConfigurationManager.AppSettings["MaxRecord"].ToString());
            EtlGlobal.LockHt = new Hashtable();
            EtlGlobal.XmlSave = ConfigurationManager.AppSettings["XmlSave"].ToString();
        }
    }
}